﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ZHDJ.Data.Models.JoinParty;
using ZHDJ.Data.Models.Org;
using ZHDJ.WebPage;

namespace ZHDJ.Web.Portal.JoinParty
{
    public partial class Activists : PortalPage
    {
        private string Id
        {
            get { return Request.QueryString["ID"].ToString(); }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (PartyJoinApplycation == null)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "tip", "errorD(1);", true);
                    return;
                }
                if (PartyOrgMember == null)
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "tip", "errorD(2);", true);

                }
                LoadData();
            }
        }
        public void LoadData()
        {
            var pub = DB.partyjoinpublicitys.Find(this.Id);
            var meet = DB.partyJoinMeetingExs.Where(a => a.AppllicationID == pub.AppllicationID && a.StepID == "JoinStep3").FirstOrDefault();
            var stand = DB.PartyJoinLinkExamples.Where(a => a.AppllicationID == pub.AppllicationID && a.CurrentStepID == "JoinStep1").FirstOrDefault();
            var stand2 = DB.PartyJoinLinkExamples.Find(pub.StandID);
            var app = DB.PartyJoinApplycation.Find(pub.AppllicationID);
            var branch = DB.PartyOrgBranchs.Find(app.BranchID);
            if (PartyOrgMember == null || PartyJoinApplycation == null)
                return;

            litUserName.Text = PartyOrgMember.UserName;
            liyUserName2.Text = PartyOrgMember.UserName;
            litSex.Text = PartyOrgMember.Gender == "1" ? "女" : "男";
            if (PartyOrgMember.Birthday != null)
                litBirthday.Text = Convert.ToDateTime(PartyOrgMember.Birthday).ToString("yyyy-MM-dd");

            litNation.Text = PartyOrgMember.Nation;

            litEducational.Text = PartyOrgMember.Educational;
            litWorkUnit.Text = PartyOrgMember.WorkUnit;
            litUnitJob.Text = PartyOrgMember.UnitJob;
            litSureDate.Text = Convert.ToDateTime(app.CreateTime).ToString("yyyy-MM-dd");
            litMeettime.Text = Convert.ToDateTime(meet.MeetingTime).ToString("yyyy-MM-dd");
            litMemberCount.Text = meet.MemberShouldBeTo;
            litQunzhong.Text = meet.PeopleIsTo;
            litMemberCount2.Text = meet.MemberIsTo;

            litAgreeCount.Text = meet.MemberAgree;
            litAgreeCount2.Text = meet.PeopleAgree;
            litNoticeTime.Text = pub.NoticeTime;
            litContact.Text = branch.LinkPhone;
            litBranch.Text = branch.BranchName;
            litNoiceTime2.Text = Convert.ToDateTime(stand2.CreateTime).ToString("yyyy-MM-dd");
            litNoticePicture.Text = stand2.Remark;
        }
        public PartyJoinApplycation PartyJoinApplycation
        {
            get
            {
                var dd = Request.QueryString["AppllicationID"];
                if (!string.IsNullOrEmpty(Request.QueryString["AppllicationID"]))
                {
                    var oModel = DB.PartyJoinApplycation.Find(Request.QueryString["AppllicationID"]);
                    if (oModel != null)
                    {
                        return oModel;
                    }
                }
                return null;
            }
        }

        public PartyOrgMember PartyOrgMember
        {
            get
            {
                if (PartyJoinApplycation == null)
                {
                    return null;
                }
                var oModel = DB.PartyOrgMembers.Find(PartyJoinApplycation.LoginID);
                if (oModel != null)
                {
                    return oModel;
                }
                return null;
            }
        }
    }
}